﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

class PauseScreen : MenuScreen
{

    private SpriteFont font, descFont;
    private Texture2D back;

    //MenuEntry backToGame, backToMainMenu, exitGameEntry;

    public PauseScreen()
        : base()
    {
        IsPopup = true;
        Globals.IsPaused = true;
        
        Direction = MenuEntryDirection.VERTICAL;

        TransitionOnTime = TimeSpan.Zero;
        TransitionOffTime = TimeSpan.Zero;
        
        selectedEntry = 0;
    }

    public override void Draw(GameTime gameTime)
    {
        SpriteBatch spriteBatch = GameSession.ScreenManager.SpriteBatch;

        spriteBatch.Begin();

        spriteBatch.Draw(back, Vector2.Zero, Color.White);
        spriteBatch.Draw(back, Vector2.Zero, Color.White);
        spriteBatch.Draw(back, Vector2.Zero, Color.White);

        string pause = "Pause";
        spriteBatch.DrawString(font, pause, new Vector2(Globals.ScreenWidth / 2 - font.MeasureString(pause).X / 2, 100), Color.Black);

        spriteBatch.End();

        base.Draw(gameTime);
    }

    public override void LoadContent()
    {
        base.LoadContent();

        font = ScreenManager.Game.Content.Load<SpriteFont>("SpriteFont2");
        descFont = ScreenManager.Game.Content.Load<SpriteFont>("SpriteFont1");
        back = ScreenManager.Game.Content.Load<Texture2D>("Textures/dark");

        CreateMenuEntries();
    }

    private void CreateMenuEntries()
    {
        string backGame = "Voltar para o jogo";
        string backToGameDescription = "Volta para o jogo do ponto em que ele foi parado.";

        MenuEntry backToGame = new MenuEntry(backGame);
        backToGame.Position = new Vector2(Globals.ScreenWidth/2 - font.MeasureString(backGame).X/2, 200);
        backToGame.Description = backToGameDescription;
        backToGame.DescriptionPosition = new Vector2(Globals.ScreenWidth / 2 - descFont.MeasureString(backToGameDescription).X / 2, 650);
        backToGame.DescriptionSize = 600;
        backToGame.DescriptionFont = descFont;
        backToGame.Font = font;
        backToGame.Selected += ExitScreen;
        MenuEntries.Add(backToGame);

        string dayMenu = "Voltar para Seleção de Dia";
        string dayMenuDescription = "Volta para o menu de Seleção de Dia e perde tudo o que já foi feito nesse dia.";

        MenuEntry backToDayMenu = new MenuEntry(dayMenu);
        backToDayMenu.Position = new Vector2(Globals.ScreenWidth / 2 - font.MeasureString(dayMenu).X / 2, 300);
        backToDayMenu.Description = dayMenuDescription;
        backToDayMenu.DescriptionPosition = new Vector2(Globals.ScreenWidth / 2 - descFont.MeasureString(dayMenuDescription).X / 2, 650);
        backToDayMenu.DescriptionSize = 600;
        backToDayMenu.Selected += ReturnDay;
        backToDayMenu.DescriptionFont = descFont;
        backToDayMenu.Font = font;
        MenuEntries.Add(backToDayMenu);

        string backMenu = "Voltar para o Menu Inicial";
        string backToMenuDescription = "Volta para o menu inicial e perde tudo o que já foi feito nesse dia.";

        MenuEntry backToMainMenu = new MenuEntry(backMenu);
        backToMainMenu.Position = new Vector2(Globals.ScreenWidth / 2 - font.MeasureString(backMenu).X / 2, 400);
        backToMainMenu.Description = backToMenuDescription;
        backToMainMenu.DescriptionPosition = new Vector2(Globals.ScreenWidth / 2 - descFont.MeasureString(backToMenuDescription).X / 2, 650);
        backToMainMenu.DescriptionSize = 600;
        backToMainMenu.Selected += ReturnMenu;
        backToMainMenu.DescriptionFont = descFont;
        backToMainMenu.Font = font;
        MenuEntries.Add(backToMainMenu);

        string exit = "Sair do jogo";
        string exitDescription = "Sai do jogo e perde tudo o que já foi feito nesse dia.";

        MenuEntry exitGameEntry = new MenuEntry(exit);
        exitGameEntry.Description = exitDescription;
        exitGameEntry.DescriptionPosition = new Vector2(Globals.ScreenWidth / 2 - descFont.MeasureString(exitDescription).X / 2, 650);
        exitGameEntry.Position = new Vector2(Globals.ScreenWidth / 2 - font.MeasureString(exit).X / 2, 500);
        exitGameEntry.DescriptionSize = 600;
        exitGameEntry.Selected += ExitGame;
        exitGameEntry.DescriptionFont = descFont;
        exitGameEntry.Font = font;
        MenuEntries.Add(exitGameEntry);
    }

    public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
    {
        base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
    }

    public override void UnloadContent()
    {
        Globals.IsPaused = false;
        base.UnloadContent();
    }

    public void Exit()
    {
        Globals.IsPaused = false;
        ExitScreen();
    }

    public override void HandleInput()
    {
        
        /*if (InputManager.IsActionPressed(InputManager.Action.Back))
        {
            Globals.IsPaused = false;
        }*/

        base.HandleInput();
    }

    public void ExitScreen(object sender, EventArgs e)
    {
        Exit();
    }

    public void ExitGame(object sender, EventArgs e)
    {
        ScreenManager.RemoveAll();
    }

    public void ReturnMenu(object sender, EventArgs e)
    {
        ScreenManager.RemoveScreen(GameSession.GamePlayScreen);
        Exit();
    }

    public void ReturnDay(object sender, EventArgs e)
    {
        GameSession.ReturnDaySelectionScreen();
        //ScreenManager.RemoveScreen(GameSession.GamePlayScreen);
        Exit();
    }
}
